﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using DataContext;

namespace BusinessLogic
{
	public class NewsBusiness
    {
        #region Field
        NewsContext newsContext = new NewsContext();
        #endregion

        #region Constructors
        public NewsBusiness() {}
		#endregion

		#region Business Methods
        /// <summary>
        /// Search News
        /// </summary>
        /// <param name="text"></param>
        /// <param name="newsID"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalRecord"></param>
        /// <returns></returns>
        public DataTable SearchNews(string text, int newsID, int currentPage, int pageSize, ref int totalRecord)
        {
            try
            {
                return newsContext.SearchNews(text, newsID, currentPage, pageSize, ref totalRecord);
            }
            catch (System.Exception)
            {
                return null;
            }
        }
        

        /// <summary>
        /// Update News Status
        /// </summary>
        /// <param name="newsID"></param>
        /// <returns></returns>
        public bool UpdateStatus(int newsID)
        {
            try
            {
                return newsContext.UpdateStatus(newsID);
            }
            catch (System.Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// Lấy NewsID mới nhất
        /// </summary>
        /// <returns></returns>
        public int SelectNewNewsID(int num)
        {
            try
            {
                return newsContext.SelectNewNewsID(num);
            }
            catch (System.Exception)
            {
                return -1;
            }
        }

        /// <summary>
        /// Lấy các bản tin khác
        /// </summary>
        /// <param name="newsID"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public DataTable SelectOtherNews(int newsID, int num)
        {
            try
            {
                return newsContext.SelectOtherNews(newsID, num);
            }
            catch (System.Exception)
            {
                return null;
            }
        }
		#endregion
	}
}
